package com.foshanshop.ejb3.impl;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import com.b2besoft.po.TestDalDs;
import com.b2besoft.po.TestOracleDs;
import com.dhgate.common.service.product.ProductService;
import com.foshanshop.ejb3.TestMutilDs;
import com.foshanshop.ejb3.dao.DAOFactory;

@Stateless
@Local({TestMutilDs.class})
@Remote({TestMutilDs.class})
public class TestMutilDsImpl implements TestMutilDs {
    
    
   @EJB
   private  ProductService productService;
    
    
    @TransactionAttribute( TransactionAttributeType.REQUIRED )
   public String saveDal(){
       TestDalDs   ds = new TestDalDs();
       ds.setName("test1");
       ds.setData("ok");
       DAOFactory.getDalDAO().save(ds);
       getDalCount();
        return "ok";
   }
    @TransactionAttribute( TransactionAttributeType.REQUIRED )
    public String saveOracle(){
        TestOracleDs   ds = new TestOracleDs();
        ds.setName("test1");
        ds.setData("ok");
         DAOFactory.getOracleDAO().save(ds);
         getOracleCount();
         return "ok";
    }
    @TransactionAttribute( TransactionAttributeType.REQUIRED )
    public String saveMutil(){
        saveDal();
        saveOracle();
        getDalCount();
        getOracleCount();
        return "ok";
    }
    @TransactionAttribute( TransactionAttributeType.REQUIRED )
    public String saveDalError() {
       getDalCount();
        saveDal();
      getDalCount();
        int j = 3/0;
        return null;
    }
    @TransactionAttribute( TransactionAttributeType.REQUIRED )
    public String saveMutilErrorAll() {
        getDalCount();
        getOracleCount();
        saveMutil();
        getDalCount();
        getOracleCount();
        int j = 3/0;
        return null;
    }

    @TransactionAttribute( TransactionAttributeType.REQUIRED )
    public String saveOracleError() {
        getOracleCount() ;
        saveOracle();
        getOracleCount() ;
        int j = 3/0;
        return null;
    }

    public int getDalCount() {
        return   DAOFactory.getDalDAO().getTestDalDs();
    }

    public int getOracleCount() {
        return   DAOFactory.getOracleDAO().getTestOracleDs();
    }
    
}
